package com.zlx.xBiaoShop.service;


import com.zlx.xBiaoShop.dao.SysUserGoodsDao;
import com.zlx.xBiaoShop.entity.Result;
import com.zlx.xBiaoShop.entity.SysUserGoods;
import com.zlx.xBiaoShop.mapper.SysUserGoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * @Description sys_user_goods 服务层
 * @author admin
 * @date 2020-12-05 17:52:12
*/
@Service
public class SysUserGoodsService {

	@Autowired
	private SysUserGoodsDao sysUserGoodsDao;
    @Autowired
    private SysUserGoodsMapper sysUserGoodsMapper;
    @Transactional
    public Result favoriteGoods(Integer userId, Integer goodsId) {
        SysUserGoods sysUserGoods = sysUserGoodsMapper.findByUserIdAndGoodsId(userId, goodsId);
        if (sysUserGoods==null){
            sysUserGoodsMapper.insert(userId,goodsId);
            return new Result(true,"收藏成功",null);
        }else {
            sysUserGoodsMapper.delete(userId,goodsId);
            return new Result(false, "取消收藏", null);
        }
    }

    public boolean isFavorate(Integer userId, Integer goodsId){
        SysUserGoods sysUserGoods = sysUserGoodsMapper.findByUserIdAndGoodsId(userId, goodsId);
        if (sysUserGoods==null){
            return false;
        }else
            return true;
    }
}
